home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb / sprite / kgdbcmd.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-16  |  3.7 KB  |  173 lines

  1. /* Commands special for KGDB.
  2. ding!
  3. */
  4.  
  5. #include "defs.h"
  6. #include "symtab.h"
  7. #include "param.h"
  8. #include "frame.h"
  9. #include "inferior.h"
  10. #include "environ.h"
  11. #include "value.h"
  12.  
  13. #include <stdio.h>
  14. #include <signal.h>
  15.  
  16.  
  17. static void
  18. attach_command (args, from_tty)
  19.      char *args;
  20.      int from_tty;
  21. {
  22.   char *exec_file;
  23.   int pid;
  24.   int remote = 0;
  25.  
  26.   dont_repeat();
  27.  
  28.   if (!args)
  29.     error_no_arg ("hostname to attach");
  30.  
  31.   while (*args == ' ' || *args == '\t') args++;
  32.  
  33.  
  34.   exec_file = (char *) get_exec_file (1);
  35.  
  36.  
  37.   printf ("Attaching remote machine %s\n",args);
  38.   remote_open (args, from_tty);
  39.   start_remote (-1);
  40. }
  41.  
  42.  
  43. static void
  44. detach_command (args, from_tty)
  45.      char *args;
  46.      int from_tty;
  47. {
  48.  
  49.   if (!inferior_pid)
  50.     error ("Not currently debugging a machine\n");
  51.   if (from_tty) {
  52.       if (args) 
  53.       printf ("Detaching with execution restarted.\n");
  54.       else
  55.       printf ("Detaching.\n");
  56.       fflush (stdout);
  57.     }
  58.    remote_detach(args);
  59.   inferior_pid = 0;
  60. }
  61.  
  62.  
  63. /* remote the remote machine. */
  64. static  void
  65. reboot_command (args, from_tty)
  66.      char *args;
  67.      int from_tty;
  68. {
  69.   dont_repeat();
  70.   if (!remote_debugging || !inferior_pid) {
  71.     error ("Not currently debugging a machine\n");
  72.   }    
  73.   remote_reboot(args);
  74. }
  75. static void
  76. pid_command (args, from_tty)
  77.      char *args;
  78.      int from_tty;
  79. {
  80.   int    pid;
  81.  
  82.   if (!args)
  83.     error_no_arg ("Must specifiy a process id");
  84.  
  85.   pid = value_as_long (evaluate_expression (parse_c_expression (args)));
  86.   if (from_tty) {
  87.       printf ("Attaching process entry: 0x%x\n", pid);
  88.   }
  89.   remote_attach(pid);
  90. }
  91.  
  92. static void
  93. version_command (args, from_tty)
  94.      char *args;
  95.      int from_tty;
  96. {
  97.   char    *version, *remote_version();
  98.   version = remote_version();
  99.   if (from_tty && version) 
  100.      printf("%s\n",version);
  101. }
  102.  
  103. static void
  104. debug_command (args, from_tty)
  105.      char *args;
  106.      int from_tty;
  107. {
  108.   int result;
  109.   if (!args)
  110.     error_no_arg ("hostname");
  111.   result = system(concat("kmsg -d ",args,""));
  112.   if (result == 0)
  113.       attach_command(args,from_tty);
  114. }
  115.  
  116. /* Set the start of the text segment  */
  117. static void
  118. text_command (args, from_tty)
  119.      char *args;
  120.      int from_tty;
  121. {
  122.   char *exec_file;
  123.   extern CORE_ADDR text_start;
  124.   extern CORE_ADDR text_end;
  125.   extern CORE_ADDR exec_data_start;
  126.   extern CORE_ADDR exec_data_end;
  127.   CORE_ADDR new_start;
  128.  
  129.  
  130.   dont_repeat();
  131.  
  132.   if (!args)
  133.     error_no_arg ("Text start address");
  134.  
  135.   while (*args == ' ' || *args == '\t') args++;
  136.  
  137.   new_start = value_as_long (evaluate_expression (parse_c_expression (args)));
  138.  
  139.  
  140.   exec_file = (char *) get_exec_file (1); /* Make sure we have an exec file */
  141.  
  142.  
  143.   text_end =  (text_end - text_start) + new_start;
  144.   text_start = new_start;
  145.   exec_data_end =  (exec_data_end - exec_data_start) + text_end;
  146.   exec_data_start =  text_end;
  147.  
  148. }
  149.  
  150.  
  151. _initialize_kgdbcmd ()
  152. {
  153.   add_com ("reboot", class_obscure, reboot_command,
  154.        "Reboot the machine being debugged.");
  155.   add_com ("pid", class_obscure, pid_command, 
  156.        "Set the process id to be debugged.");
  157.   add_com ("version", class_obscure, version_command, 
  158.        "Print the version string of the kernel being debugged.");
  159.   add_com ("debug", class_obscure, debug_command, 
  160.        "Force the specified host into the debugger and attach it.");
  161.   add_com ("text", class_obscure, text_command, 
  162.        "Specify the starting address of the text segment.");
  163.  add_com ("attach", class_run, attach_command,
  164.        "Attach to a machine in to debugger.\n\
  165. Before using \"attach\", you must use the \"exec-file\" command\n\
  166. to specify the program running in the process,\n\
  167. and the \"symbol-file\" command to load its symbol table.");
  168.   add_com ("detach", class_run, detach_command,
  169.        "Detach the machine previously attached.\n\
  170. If a non zero argument is specified, the machine execution is not resumed.");
  171. }
  172.  
  173.